package com.example.user_service.dao;

import com.example.user_service.dao.dt.FindUserById;
import com.example.user_service.vo.*;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import com.example.user_service.vo.Administrator;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
@Mapper
public interface UserSelect {
    //gfc 管理员登录
    @Select("select account,pawd from administrator where account=#{account} and pawd = #{pawd} ")
    Administrator login_Administrator(Administrator administrator);

    //gfc 查询手机号是否被注册
    @Select("select count(1) from user_login where tel = #{tel}")
    int login_istel(String tel);

    //gfc 查询账号否被注册
    @Select("select count(1) from user_login where account = #{name}")
    int login_isname(String name);


    //gfc 通过手机查询userid
    @Select("select user_id from user_login where tel = #{tel}")
    Integer insert_select_userid(String tel);

    //gfc 登录
    @SelectProvider(type = FindUserById.class, method = "findUserById")
    UserVO is_login(String name, String pawd, String tyle);



    /* 条件查询管理员
     * @author Liu
     * @date 2021/12/14 23:01
     * @param null
     * @return
     * @throws
     * @since
     */
    @Select({"<script>",
            "SELECT a.id,a.account,a.pawd,a.state,a.createdatetime,r.role_name  FROM administrator as a ,t_role as r where a.role = r.id",
            "<if test='createdatestr!=\"\" and enddatestr!=\"\" and account!=\"\"' >",
            " WHERE createdatetime &gt;= '${createdatestr}' AND createdatetime &lt;= '${enddatestr}' and account like '%${account}%' ORDER BY createdatetime DESC",
            "</if>",
            "<if test='createdatestr!=\"\" and enddatestr==\"\" and account==\"\"' >",
            " WHERE createdatetime &gt;= '${createdatestr}'  ORDER BY createdatetime DESC",
            "</if>",
            "<if test='createdatestr!=\"\"  and account!=\"\" and enddatestr==\"\"' >",
            " WHERE createdatetime &gt;= '${createdatestr}'  and account like '%${account}%' ORDER BY createdatetime DESC",
            "</if>",
            "<if test='createdatestr==\"\"  and account!=\"\" and enddatestr==\"\"' >",
            " WHERE  account like '%${account}%' ORDER BY createdatetime DESC",
            "</if>",
            "<if test='createdatestr!=\"\"  and account==\"\" and enddatestr!=\"\"' >",
            " WHERE  createdatetime &gt;= '${createdatestr}' AND createdatetime &lt;= '${enddatestr}' ORDER BY createdatetime DESC",
            "</if>",
            "</script>"
    })
    List<Administrator> AdministratorSelect(@Param("createdatestr") String createdatestr,@Param("enddatestr") String enddatestr,@Param("account") String account);

    /* 校验管理员账号是否存在
     * @author Liu
     * @date 2021/12/15 0:10
     * @param null
     * @return
     * @throws
     * @since
     */
    @Select("select account,pawd from administrator where account=#{account} ")
    Administrator check_Administrator(Administrator administrator);


    /* 查询用户积分
     * @author Liu
     * @date 2021/12/17 11:23
     * @param null
     * @return
     * @throws
     * @since
     */
    @Select("select * from user_member where user_id = ${userid}")
    User_Member select_member_existing_integral(int userid);

    /* 查询我的足迹
     * @author Liu
     * @date 2021/12/17 11:49
     * @param null
     * @return
     * @throws
     * @since
     */
    @Select("select * from my_tracks where user_id = ${userid}")
    List<MyTracks> select_my_tracks(int userid);
}
